# -*- codeing = utf-8 -*-
# @Time : 2024/3/14 19:18
# @Author : huangjing
# @File : base_study.py
# @Software : PyCharm
import copy
from datetime import datetime
class BaseStudy():

    #字符串去重+排序
    def demo01(self,s:str) -> list:
        l = list(set([i for i in s]))
        l.sort(reverse=False)
        return l

    # 1到100内的质数
    def demo02(self,n:int) -> list:
        l = []
        for i in range(2,n):
            f = True
            for j in range(2,int(i**0.5)+1):
                if i%j == 0:
                    f = False
                    break
                # else:
                #     f = True
            if f:
                l.append(i)
        return l
    #斐波拉契数列
    def demo03(self,n:int) -> int:
        if n == 0 or n == 1:
            return 0
        elif n == 2:
            return 1
        else:
            return self.demo03(n-1) + self.demo03(n-2)
    # 回文
    def demo04(self,s:str) -> str:
        l = str(s).split(' ')
        l.reverse()
        return ' '.join(l)
    # 字母出现次数
    def demo05(self,s:str) -> dict:
        l = [i for i in str(s)]
        d = {}
        for i in l:
            if d.get(i) == None:
                d[i] = 1
            else:
                d[i] += 1
        return d
    # 取出奇数和偶数
    def demo06(self,n:list) -> tuple:
        a,b = [i for i in list(n) if i % 2 == 0],[i for i in list(n) if i % 2 != 0]
        return a,b
    # 素数之积
    def demo07(self,n:int) -> tuple:
        for i in range(2,n):
            if n % i == 0:
                return i,int(n/i)
        return -1,-1
    #列表中找出两个数的和为目标数
    def demo08(self,l:list,t:int) -> list:
        r = []
        for i in l:
            if t > i and l.count(t-i)>0:
                if r != []:
                    f = True
                    for j in r:
                        if j.count(i) != 0:
                            f = False
                            break
                    if f and l[l.index(i)] != l[l.index(t - i)]:
                        r.append((l[l.index(i)], l[l.index(t - i)]))
                else:
                    r.append((l[l.index(i)],l[l.index(t-i)]))
        return r
    #冒泡排序
    def demo09(self,l:list) -> list:
        s = len(l)
        for i in range(0,s-1):
            for j in range(i+1,s):
                if l[i] > l[j]:
                    l[j],l[i] = l[i],l[j]
        return l
    def demo091(self,l:list):
        s = len(l)
        for i in range(0,s-1):
            for j in range(0,s-1-i):
                if l[j] > l[j+1]:
                    l[j],l[j+1] = l[j+1],l[j]
        print(l)
    #十个字符串用'.'拼接,将前两个改成'-'拼接
    def demo10(self):
        s = 'ab.cd.efg.aa.cc.vv.bb.ccc.ee.ww'
        a = s.index('.')
        print(a)
        r = s.replace('.','-',1)
        print(r)

    # 十个字符串用'.'拼接,将第四,五个改成'-'拼接
    def demo101(self):
        s = 'ab.cd.efg.aa.cc.vv.bb.ccc.ee.ww'
        a = s.split('.')
        r = ''
        for i in range(len(a)-2):
            if i != 3:
                r += a[i] + '.'
            else:
                r += a[i] + '-'
        r += a[len(a)-1]
        print(r)
    #1，2，3加起来等于100有多少种可能
    #暴力解法
    def demo11(self,n):
        c = 0
        x = 0
        l = []
        while x <= n:
            y = 0
            while y <= n/2:
                z = 0
                while z <= n/3:
                    if (x+2*y+3*z) == 100:
                        c += 1
                        l.append([x,y,z])
                        break
                    z += 1
                y += 1
            x += 1
        print(l)
        return c
    #使用二分查找法在有序的数组中找出
    def demo12(self,l,t,w,n):
        if t > w:
            return None
        h = int((w+t)/2)
        if l[h] == n:
            return h
        elif n > l[h]:
            return self.demo12(l,h+1,w,n)
        else:
            return self.demo12(l,t,h-1,n)
    def demo120(self,l,n):
        t = 0
        w = len(l)-1
        while t < w:
            h = int((w+t)/2)
            if l[h] == n:
                return h
            elif l[h] < n:
                t = h+1
            else:
                w = h-1
        return -1
    #使用递归的方式实现阶乘
    def demo13(self,n):
        if n == 1 or n == 0:
            return 1
        else:
            return n * self.demo13(n-1)
    #字符串匹配
    def demo14(self,s1:str,s2:str):
        if s1.count(s2) > 0:
            l = s1.split(s2)
            return len(l[0])
        else:
            return None
    #字符串暴力破解
    def demo140(self,s1:str,s2:str):
        lenr = len(s1)
        lenl = len(s2)
        r = 0
        l = 0
        while r < lenr and l < lenl:
            if s1[r] == s2[l]:
                r += 1
                l += 1
            else:
                r = r - l + 1
                l = 0
            if l == lenl:
                return r - l
        return -1
    #给定一个数n，k，求0-n中k出现了几次
    def demo15(self,n,k):
        l = [str(i) for i in range(0,n+1)]
        s = ''.join(l)
        return s.count(str(k))
    #三天打鱼两天晒网，1990-01-01开始，计算输入的日期是打鱼还是晒网
    def demo16(self,d):
        date_info = '%Y-%m-%d'
        d1 = datetime.strptime('1990-01-01',date_info)
        d2 = datetime.strptime(d,date_info)
        diff = d2-d1
        print(diff.days)
        if diff.days % 5 == 0 or diff.days % 4 == 0:
            return '晒网'
        else:
            return '打鱼'

if __name__ == '__main__':
    b = BaseStudy()
    # print(b.demo01('asdsasawqec'))
    print(b.demo02(100))
    # print([b.demo03(i) for i in range(1, 10)])
    # print(b.demo04('what‘s you name'))
    # print(b.demo05('adacbffbcolbqa'))
    # t = b.demo06([i for i in range(1,11)])
    # print('偶数：{};奇数：{}'.format(list(t)[0],list(t)[1]))
    # print(b.demo07(35))
    # print(b.demo08([1, 2, 3, 5, 4, 8, 6, 9, 7], 15))
    # print(b.demo09([2, 9, 7, 6, 8, 11, 6, 5, 4, 3,1]))
    # b.demo091([2, 9, 7, 6, 8, 11, 6, 5, 4, 3,1])
    # b.demo101()
    # print(b.demo11(100))
    # print(b.demo12([0, 2, 4, 6, 8, 10, 12, 14, 16, 18], 0, 9, 14))
    # print(b.demo120([0, 2, 4, 6, 8, 10, 12, 14, 16, 18], 14))
    # print(b.demo13(5))
    # print(b.demo140('hellolell', 'lell'))
    # print(b.demo15(20, 2))
    # print(b.demo16('2024-03-26'))
    # print({1, 2}.union({4, 5}))